<template>
  <a-modal
    :title="title"
    :width="1400"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="48">
          <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="formId">
          <a-input placeholder="请输入formId" v-decorator="['formId', {}]" />
        </a-form-item>-->
        <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="流程ID">
          <a-input placeholder="请输入流程ID" v-decorator="['processId', {}]" />
        </a-form-item>-->
        <a-divider>节点基本信息</a-divider>
          <a-col :span="12">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="节点名称">
          <a-input placeholder="请输入节点名称" v-decorator="['processNodeName', {}]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="节点编码">
          <a-input placeholder="请输入节点编码" v-decorator="['processNodeCode', {}]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="PC表单地址">
          <a-input placeholder="请输入PC表单地址" v-decorator="['modelAndView', {}]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="移动表单地址">
          <a-input placeholder="请输入移动表单地址" v-decorator="['modelAndViewMobile', {}]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="排序">
          <a-input-number
            :max="99999999"
            :min="0"
            v-decorator="['sort', {}]"
            placeholder="排序"
          />（用于流程发起时节点排序的显示）
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="超时提醒（时）">
          <a-input-number v-decorator="[ 'nodeTimeout', {}]" :min="0"/> （单位小时，0表示不提醒）
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="节点类型">
          <j-dict-select-tag  v-decorator="[ 'flowType', {}]" :trigger-change="true"   dictCode="sys_flow_type"/>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="数据来源">
          <j-dict-select-tag  v-decorator="[ 'dataSource', {}]" :trigger-change="true"   dictCode="post_data_source"/>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="流程跳过类型">
          <j-dict-select-tag  v-decorator="[ 'flowJumpType', {}]" :trigger-change="true"   dictCode="flow_jump_type"/>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="节点为空提示">
          <a-textarea placeholder="请输入节点为空提示" v-decorator="['emptyMessage', {}]" />
        </a-form-item>
      </a-col>
      <a-col :span="24">
      <!-- 子表单区域 -->
      <j-editable-table
        @deleted="deletedCol"
        @added="addCol"
        v-show="this.model.flowType!='INFORM'"
        ref="editableTable2"
        :loading="loading"
        :columns="columns1"
        :dataSource="dataSource2"
        :maxHeight="300"
        :rowNumber="true"
        :rowSelection="true"
        @valueChange="handleValueChange"
        :actionButton="true">
        <template #defaultValue="props">
          <template v-if="dataSource2.filter(item => item.id==props.rowId)[0]!=null && dataSource2.filter(item => item.id==props.rowId)[0].fieldType=='postCode'">
            <j-search-select
              v-model="field.postCode"
              dict="sys_position,name,code,del_flag = 0 and audit_status=2"
              placeholder="请选择岗位"
              @change="valueChange($event,props)"
            />
          </template>
          <template v-else-if="dataSource2.filter(item => item.id==props.rowId)[0]!=null && dataSource2.filter(item => item.id==props.rowId)[0].fieldType=='departId'">
            <j-select-depart  v-model="field.departId"  @change="valueChange($event,props)"/>
          </template>
          <template v-else-if="dataSource2.filter(item => item.id==props.rowId)[0]!=null && dataSource2.filter(item => item.id==props.rowId)[0].fieldType=='teamId'">
            <select-team-input :query-type="'parent'" @change="valueChange($event,props)" v-model="field.teamId" :tdlx="3" />
          </template>
          <template v-else-if="dataSource2.filter(item => item.id==props.rowId)[0]!=null && dataSource2.filter(item => item.id==props.rowId)[0].fieldType=='company'">
            <select-Company-input v-model="field.company" @change="valueChange($event,props)"/>
          </template>
          <template v-else-if="dataSource2.filter(item => item.id==props.rowId)[0]!=null && dataSource2.filter(item => item.id==props.rowId)[0].fieldType=='positionCategory'">
            <j-search-select  v-model="field.positionCategory" @change="valueChange($event,props)"  dict="position_category"/>
          </template>
          <template v-else-if="dataSource2.filter(item => item.id==props.rowId)[0]!=null && dataSource2.filter(item => item.id==props.rowId)[0].fieldType=='positionLevelId'">
            <j-search-select  v-model="field.positionLevelId" @change="valueChange($event,props)"  dict="erp_org_position_level,level_name,id,del_flag = 0 and audit_status=2"/>
          </template>
          <template v-else-if="dataSource2.filter(item => item.id==props.rowId)[0]!=null && dataSource2.filter(item => item.id==props.rowId)[0].fieldType=='username'">
            <j-select-user-by-dep v-model="field.username" :multi="true"   @change="valueChange($event,props)"></j-select-user-by-dep>
          </template>
          <template v-else-if="dataSource2.filter(item => item.id==props.rowId)[0]!=null && dataSource2.filter(item => item.id==props.rowId)[0].fieldType=='userId'">
            <select-user-by-dep  :multi="true"  @change="valueChange($event,props)"
                    v-model="field.userId" ></select-user-by-dep>
          </template>
          <template v-else-if="dataSource2.filter(item => item.id==props.rowId)[0]!=null && dataSource2.filter(item => item.id==props.rowId)[0].fieldType">
            <a-input placeholder="请输入默认值" v-model="field[dataSource2.filter(item => item.id==props.rowId)[0].fieldType]"  @change="valueSetChange($event,dataSource2.filter(item => item.id==props.rowId)[0].fieldType,props)"/>
          </template>
        </template>
      </j-editable-table>
      <template>
        <div>1.若填写数据库字段和默认值同时存在，以数据库字段为优先</div>
        <div>2.无数据库字段时，取默认值</div>
      </template>
      </a-col>
      <!-- <a-col :span="8">
          <a-form-model-item label="岗位" :labelCol="labelCol" :wrapperCol="wrapperCol" >
            <j-search-select
              v-decorator="['postCode', {}]"
              dict="sys_position,name,code,del_flag = 0 and audit_status=2"
              placeholder="请选择岗位"
            />
          </a-form-model-item>
      </a-col>
      <a-col :span="8">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="属性类型">
          <j-dict-select-tag @change="fieldTypeChange"  v-decorator="[ 'fieldType', {}]" :trigger-change="true"   dictCode="field_type"/>
        </a-form-item>
      </a-col>
      <a-col :span="8">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="属性字段（数据库字段）"
        >
          <a-input placeholder="请输入属性字段" v-decorator="['fieldName', {}]" />
        </a-form-item>
      </a-col>
      <a-col :span="8" v-show="this.userFlag">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="指定人账号">
          <a-input  placeholder="请输入指定人账号" v-decorator="['expressionName', {}]" />
        </a-form-item>
      </a-col>

      <a-col :span="8">
        <a-form-item
                 :labelCol="labelCol"
                 :wrapperCol="wrapperCol"
                 label="审批人部门">
          <j-select-depart   v-decorator="[ 'departId', {}]"   />
        </a-form-item>
      </a-col> -->
      <a-divider>节点权限</a-divider>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="是否为同意节点">
            <a-radio-group name="radioGroup"   v-decorator="['isOnlySubmit']"  >
              <a-radio :value="'1'">
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="是否为会签节点">
            <a-radio-group name="radioGroup"   v-decorator="['isMultAssignee']"  >
              <a-radio :value="'1'">
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="是否顺序审批">
            <a-radio-group name="radioGroup"   v-decorator="['isSequenceApprove']"  >
              <a-radio :value="'1'">
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="是否支持退回指定节点">
            <a-radio-group name="radioGroup" v-decorator="['isRejectNode']" @change="optionRejectNode" >
              <a-radio :value="'1'">
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="8" v-if="rejectNodeFlag">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="支持退回的节点">
            <j-multi-select-tag
              v-decorator="[ 'rejectNodeTaskId', {}]" :trigger-change="true"
                  :dictCode="nodeTask"
                  placeholder="请选择节点">
                </j-multi-select-tag>
            <span>注：若不选择，支持退回所有的历史审批节点</span>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="用户是否可代理">
            <a-radio-group name="radioGroup"   v-decorator="['isAuth']"  >
              <a-radio :value="'1'">
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="知会是否为自定义">
            <a-radio-group name="radioGroup"   v-decorator="['notifyIsCustom']"  >
              <a-radio :value="'1'">
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="用户是否可选节点">
            <a-radio-group name="radioGroup"   v-decorator="['isSelectDisabled']"  >
              <a-radio :value="'1'">
                可选
              </a-radio>
              <a-radio :value="'0'">
                不可选
              </a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="是否校验表单必填">
            <a-radio-group name="radioGroup"   v-decorator="['isValForm']"  >
              <a-radio :value="'1'">
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="是否显示节点">
            <a-radio-group name="radioGroup"   v-decorator="['isShow']"  >
              <a-radio :value="'1'" default-checked>
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
          </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="是否允许忽略">
            <a-radio-group name="radioGroup"   v-decorator="['isIgnore']"  >
              <a-radio :value="'1'" default-checked>
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
          </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="是否允许转办">
            <a-radio-group name="radioGroup"   v-decorator="['isTransfer']"  >
              <a-radio :value="'1'" default-checked>
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="是否允许委托">
            <a-radio-group name="radioGroup"   v-decorator="['isEntrust']"  >
              <a-radio :value="'1'" default-checked>
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="是否允许转发">
            <a-radio-group name="radioGroup"   v-decorator="['isForward']"  >
              <a-radio :value="'1'" default-checked>
                是
              </a-radio>
              <a-radio :value="'0'">
                否
              </a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
      </a-row>

      </a-form>
      <!-- 子表单区域 -->
      <a-tabs v-model="activeKey" v-if="!showFlag" >
        <a-tab-pane tab="补充功能" key="1" :forceRender="true">
          <j-editable-table
            ref="editableTable1"
            :loading="loading"
            :columns="columns"
            :dataSource="dataSource"
            :maxHeight="300"
            :rowNumber="true"
            :rowSelection="true"
            :actionButton="true"
            :dragSort="true"
            @valueChange="handleValueChange1"
            ></j-editable-table>
            <template>
              <div>1.直接取用户，无需配置其他</div>
              <div>2.按照类型配置取人（需要结合公司/团队/岗位/部门/数据来源）</div>
              <div>3.按照自定义加强json配置(支持从表单中获取，仅仅发起的表单数据时有效)  实例：{"id":"123456789", "teamId": "${teamId}"}</div>
            </template>
        </a-tab-pane>
      </a-tabs>
    </a-spin>
  </a-modal>
</template>

<script>
import { getAction, httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import { FormTypes, getRefPromise, VALIDATE_NO_PASSED, validateFormAndTables } from '@/utils/JEditableTableUtil';
import JEditableTable from '@/components/jeecg/JEditableTable'
import JDate from '@comp/jeecg/JDate';
import JMultiSelectTag from '@/components/dict/JMultiSelectTag'
import JSearchSelect from '@/views/scy/components/JSearchSelect.vue'
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput';
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'


export default {
    name: "ExtActProcessNodeModal",
    components: {
      JDate, JEditableTable,JMultiSelectTag, JSearchSelect,SelectCompanyInput,SelectTeamInput,SelectUserByDep
    },
    props:{
      processId:{
        type: String,
        default: ''
      }
    },
    data () {
      return {
        dictOptions:{},
        showFlag: false,
        activeKey: '1',
        activeKey1:'1',
        title:"操作",
        visible: false,
        model: {},
        userFlag: false,
        labelCol: {
        },
        field:{},
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 }
        },
        loading: false,
        dataSource2: [],
        dataSource: [],
        columns: [
          {
            title: '类型',
            key: 'flowType',
            width: '10%',
            type: FormTypes.select,
            dictCode: 'sys_flow_type',
            defaultValue: '',
            placeholder: '请选择${title}'
          },
          {
            title: '公司',
            key: 'companyId',
            width: '10%',
            type: FormTypes.sel_search,
            dictCode: 'erp_company_files,file_name,id',
            defaultValue: '',
            placeholder: '请输入${title}'
          },
          {
            title: '团队',
            key: 'teamId',
            width: '10%',
            type: FormTypes.sel_search,
            dictCode: 'erp_omc_team_manager,alias_name,id,team_type=1 and team_level=1',
            defaultValue: '',
            placeholder: '请输入${title}'
          },
          {
            title: '部门',
            key: 'departId',
            width: '12%',
            type: FormTypes.sel_depart,
            defaultValue: '',
            placeholder: '请输入${title}'
          },
          {
            title: '岗位序列',
            key: 'positionCategory',
            width: '10%',
            dictCode: 'position_category',
            type: FormTypes.select,
            defaultValue: '',
            placeholder: '请输入${title}'
          },
          {
            title: '职务级别',
            key: 'positionLevelId',
            width: '10%',
            dictCode: 'erp_org_position_level,level_name,id,del_flag = 0 and audit_status=2',
            type: FormTypes.select,
            defaultValue: '',
            placeholder: '请输入${title}'
          },
          {
            title: '岗位',
            key: 'postCode',
            width: '10%',
            dictCode: 'sys_position,name,code,del_flag = 0 and audit_status=2',
            type: FormTypes.select,
            defaultValue: '',
            placeholder: '请输入${title}'
          },
          {
            title: '数据来源',
            key: 'dataSource',
            width: '10%',
            dictCode: 'post_data_source',
            type: FormTypes.select,
            defaultValue: '',
            placeholder: '请选择${title}'
          },
          {
            title: '指定用户',
            key: 'username',
            width: '20%',
            type: FormTypes.sel_user,
            defaultValue: '',
            placeholder: '请输入${title}'
          },
          {
            title: '是否自定义',
            key: 'sex',
            width: '10%',
            type: FormTypes.select,
            dictCode: 'YES_OR_NO',
            defaultValue: '0',
            placeholder: '请选择${title}'
          },
          {
            title: '表达式',
            key: 'expression',
            width: '16%',
            type: FormTypes.input,
            defaultValue: '',
            placeholder: '请输入${title}'
          },
          {
            title: 'json增强',
            key: 'jsonParams',
            width: '15%',
            type: FormTypes.input,
            defaultValue: '',
            placeholder: '请输入${title}'
          },
          {
            title: '备注',
            key: 'remark',
            width: '10%',
            type: FormTypes.input,
            defaultValue: '',
            placeholder: '请输入${title}'
          },
        ],
        columns1: [
        {
            title: '属性名称',
            key: 'fieldType',
            width: '20%',
            type: FormTypes.select,
            dictCode: 'field_type',
            defaultValue: '',
            placeholder: '请选择${title}',
          },
          {
            title: '数据库字段',
            key: 'fieldName',
            width: '30%',
            type: FormTypes.input,
            defaultValue: '',
            placeholder: '请输入${title}'
          },
          // {
          //   title: '默认值',
          //   key: 'defaultValue',
          //   width: '30%',
          //   type: FormTypes.input,
          //   defaultValue: '',
          //   placeholder: '请选择${title}',
          // },
          {
            title: '默认值',
            key: 'defaultValue',
            width: '30%',
            type: FormTypes.slot,
            defaultValue: '',
            placeholder: '请选择${title}',
          },

        ],
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/api/erpmng/act/process/extActProcessNode/add",
          edit: "/api/erpmng/act/process/extActProcessNode/edit",
          queryProcessNodeDtListByProcessId: '/api/erpmng/act/process/extActProcessNode/queryProcessNodeDtListByProcessId',
          queryProcessNodeDt2ListByProcessId: '/api/erpmng/act/process/extActProcessNode/queryProcessNodeDt2ListByProcessId'
        },
        nodeTask:"ext_act_process_node,process_node_name,process_node_code,task_type = 'org.activiti.bpmn.model.UserTask' and process_id="+this.processId,
        rejectNodeFlag:false
      }
    },
    created () {
      this.initDictConfig();
    },
    methods: {
      // 加载数据字典信息
      initDictConfig() {
        initDictOptions('field_type').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'fieldType', res.result)
          }
        })
      },
      optionRejectNode(e){
        let value=e.target.value;
        this.rejectNodeFlag=(value=='1'?true:false);
        if(!this.rejectNodeFlag){
          this.model.rejectNodeTaskId='';
        }
      },
      deletedCol(data){
        for(var i=0;i<data.length;i++){
          for(var j=0;j<this.dataSource2.length;j++){
            if(data[i]==this.dataSource2[j].id){
            this.dataSource2.splice(j, 1);
            }
          }
        }
      },
      addCol(data){
        console.log(data)
      },
      add (processId) {
        this.edit({processId:processId});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        // 根据属性类型 显示/隐藏 文本
        this.fieldTypeChange(record.fieldType)
        //加载知会明细
        if (this.model){
          if (this.model.flowType) {
            getAction(this.url.queryProcessNodeDtListByProcessId, { id: record.id }).then((res) => {
              if (res.success) {
                 this.dataSource = res.result;
              }
            })
            getAction(this.url.queryProcessNodeDt2ListByProcessId, { id: record.id }).then((res) => {
              if (res.success) {
                 this.dataSource2 = res.result;
                  if(this.dataSource2.length>0){
                    let fieldType=[];
                    this.dictOptions['fieldType'].forEach(item=>{
                      fieldType.push(item.value)
                    })
                    this.dataSource2.forEach(item=>{
                      for(let i=0;i<fieldType.length;i++){
                        if(item.fieldType==fieldType[i]){
                          this.$set(this.field,fieldType[i],item.defaultValue)
                        }
                      }
                    })
                  }else{
                    this.dataSource2=[]
                  }
              }else{
                this.dataSource2=[]
              }
            })
          }else{
            this.dataSource2=[]
          }
        }else{
            this.dataSource2=[]
        }
        this.rejectNodeFlag=this.model.isRejectNode=='1'?true:false;
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'flowJumpType','emptyMessage','dataSource','isRejectNode','isSequenceApprove','rejectNodeTaskId', 'isShow', 'isAuth','nodeBranch', 'departId' ,'flowType','formId','processId','processNodeCode','processNodeName','modelAndView','isValForm','modelAndViewMobile', 'isSelectDisabled','nodeTimeout','nodeBpmStatus','expressionName','isOnlySubmit','notifyIsCustom','isIgnore','isTransfer','isEntrust','isForward','isMultAssignee','sort','postCode','fieldType','fieldName'))
		  //时间格式化
        });

      },
      valueChange(data,event){
        const { rowId, target } = event
        target.setValues([{
          rowKey: rowId,
          values: { defaultValue:data}
        }])
      },
      valueSetChange(data,name,event){
        const { rowId, target } = event
        target.setValues([{
          rowKey: rowId,
          values: { defaultValue:this.field[name]}
        }])
      },
      handleValueChange(event) {
        const { type, row, rowId,column, value, target } = event
        if (column.key === 'fieldType') {
          let rowIdData=rowId
          if(!rowId){
            rowIdData=row.id
          }
          let data=this.dataSource2.filter(item=>item.id==rowIdData)
          if(data.length>0){
            this.dataSource2.filter(item=>item.id==rowIdData)[0].fieldType=value;
          }else{
            this.dataSource2.push(row)
          }
        }
      },
      close () {
        this.$emit('close');
        this.getAllTable().then(editableTables => {
          editableTables[0].initialize()
          editableTables[1].initialize()
        })
        this.visible = false;
      },
      // 获取所有的editableTable实例
      getAllTable() {
        return Promise.all([
          getRefPromise(this, 'editableTable1'),
          getRefPromise(this, 'editableTable2')
        ])
      },
      handleValueChange1(event) {
        const { type, row, column, value, target } = event
        if(column.key === 'postCode'){
          // console.log(target.get)
        }

      },
      handleOk () {
        this.validateFields()
      },
      /** 触发表单验证 */
      validateFields() {
        this.getAllTable().then(tables => {
          /** 一次性验证主表和所有的次表 */
          return validateFormAndTables(this.form, tables)
        }).then(allValues => {
          let formData = this.classifyIntoFormData(allValues)
          // 发起请求
          return this.requestAddOrEdit(formData)
        }).catch(e => {
          if (e.error === VALIDATE_NO_PASSED) {
            // 如果有未通过表单验证的子表，就自动跳转到它所在的tab
            this.activeKey = e.index == null ? this.activeKey : (e.index + 1).toString()
          } else {
            console.error(e)
          }
        })
      },
      handleCancel () {
        this.close()
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let orderMain = Object.assign(this.model, allValues.formValue)
        //时间格式化
        return {
          ...orderMain,
          nodeDt1List: allValues.tablesValue[0].values,
          nodeDt2List: allValues.tablesValue[1].values
        }
      },
      fieldTypeChange(val) {
        if (val === 'username') {
          this.userFlag = true
        } else {
          this.userFlag = false
        }
      },
      /** 发起新增或修改的请求 */
      requestAddOrEdit(formData) {
        if(formData.dataSource==undefined){
          formData.dataSource=null;
        }
        let url = this.url.add, method = 'post'
        if (this.model.id) {
          url = this.url.edit
          method = 'put'
        }
        this.confirmLoading = true
        httpAction(url, formData, method).then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.field={}
            this.$emit('ok')
            this.close()
          } else {
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.confirmLoading = false
        })
      },
      handleDelete(props) {
        let { rowId, target } = props
      },
    }
  }
</script>

<style scoped>

</style>